package com.hdu.hot100.stack;

public class lc20 {
    class Solution {
        public boolean isValid(String s) {
            char[] stack = new char[s.length()];
            int r = 0;
            for (char c : s.toCharArray())
            {
                if (c == '(')
                {
                    stack[r++] = ')';
                }
                else if (c == '{')
                {
                    stack[r++] = '}';
                }
                else if (c == '[')
                {
                    stack[r++] = ']';
                }
                else
                {
                    if (r == 0)
                    {
                        return false;
                    }
                    if (stack[--r] != c)
                    {
                        return false;
                    }
                }
            }
            return r == 0;
        }
    }
}
